package com.bailian.system.service.impl;

import java.util.List;
import java.util.ArrayList;
import com.bailian.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.bailian.system.mapper.BlParkAreaMapper;
import com.bailian.system.domain.BlParkArea;
import com.bailian.system.service.IBlParkAreaService;
import com.bailian.system.domain.vo.BlParkAreaVo;
import com.bailian.system.domain.vo.BlParkVo;
import com.bailian.system.service.IBlParkService;

/**
 * 园区区域Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-08-12
 */
@Service
public class BlParkAreaServiceImpl implements IBlParkAreaService 
{
    @Autowired
    private BlParkAreaMapper blParkAreaMapper;

    @Autowired
    private IBlParkService parkService;

    /**
     * 查询园区区域
     * 
     * @param id 园区区域主键
     * @return 园区区域
     */
    @Override
    public BlParkArea selectBlParkAreaById(Long id)
    {
        return blParkAreaMapper.selectBlParkAreaById(id);
    }

    /**
     * 查询园区区域列表
     * 
     * @param blParkArea 园区区域
     * @return 园区区域
     */
    @Override
    public List<BlParkArea> selectBlParkAreaList(BlParkArea blParkArea)
    {
        return blParkAreaMapper.selectBlParkAreaList(blParkArea);
    }

    @Override
    public List<BlParkAreaVo> selectBlParkAreaVoList(BlParkArea blParkArea)
    {
        List<BlParkAreaVo> areaVoList = blParkAreaMapper.selectBlParkAreaVoList(blParkArea);
        if (areaVoList == null || areaVoList.isEmpty()) {
            return areaVoList;
        }
        for (BlParkAreaVo areaVo : areaVoList) {
            List<BlParkVo> parks = areaVo.getParks();
            if (parks == null || parks.isEmpty()) {
                continue;
            }
            List<BlParkVo> enrichedParks = new ArrayList<>(parks.size());
            for (BlParkVo park : parks) {
                BlParkVo full = parkService.selectById(park.getParkId());
                enrichedParks.add(full != null ? full : park);
            }
            areaVo.setParks(enrichedParks);
        }
        return areaVoList;
    }

    /**
     * 新增园区区域
     * 
     * @param blParkArea 园区区域
     * @return 结果
     */
    @Override
    public int insertBlParkArea(BlParkArea blParkArea)
    {
        blParkArea.setCreateTime(DateUtils.getNowDate());
        return blParkAreaMapper.insertBlParkArea(blParkArea);
    }

    /**
     * 修改园区区域
     * 
     * @param blParkArea 园区区域
     * @return 结果
     */
    @Override
    public int updateBlParkArea(BlParkArea blParkArea)
    {
        blParkArea.setUpdateTime(DateUtils.getNowDate());
        return blParkAreaMapper.updateBlParkArea(blParkArea);
    }

    /**
     * 批量删除园区区域
     * 
     * @param ids 需要删除的园区区域主键
     * @return 结果
     */
    @Override
    public int deleteBlParkAreaByIds(Long[] ids)
    {
        return blParkAreaMapper.deleteBlParkAreaByIds(ids);
    }

    /**
     * 删除园区区域信息
     * 
     * @param id 园区区域主键
     * @return 结果
     */
    @Override
    public int deleteBlParkAreaById(Long id)
    {
        return blParkAreaMapper.deleteBlParkAreaById(id);
    }
}
